-- 基础状态类

-- 模块定义
local M = 
{
    _base_class = require "objects.Object",
    _class_name = "states.BaseState",
};
setmetatable (M, {__index = _G;});
_ENV = M;

-- 引用模块
local Tools = require "tools.CommonTools";

-- 方法定义
operation_table = Tools.CreateOperationTable (_base_class);

-- 获取状态名称。这个比较重要，状态机使用状态名来维护状态列表。
function operation_table.GetName (self)
    error ("base_state: get_name should be override in subclass.");
end;

-- 设置所属状态机
function operation_table.SetFsm (self, fsm)
    self._fsm = fsm;
end;

-- 启动状态
function operation_table.Start (self) 
    -- 子类当重写该方法
    self:_SetRunning (true);
end;

-- 停止状态
function operation_table.stop (self)
    -- 子类当重写该方法
    self:_SetRunning (false);
end;

-- 更新状态
function operation_table.Update (self, current_time, delta_time)
    -- 子类当重写该方法
end;

-- 设置当前状态为运行
function operation_table._SetRunning (self, running)
    self._isRunning = running;
end;

-- 设置当前状态为停止
function operation_table._IsRunning (self)
    return self._isRunning;
end;

-- 构造方法
function NewBaseState (entity)
    local instance = _base_class.NewObject ();
    Tools.PrepareInstance (M, instance);
    
    -- 私有成员
    instance._entity = entity;
    instance._isRunning = false;
    instance._fsm = nil;
    return instance;
end;

return M;
